const http = require('http')
const Router = require('./router')

class App {
  router = new Router()

  get(path, ...handler) {
    this.router.add(path, 'GET', handler)
  }

  listen(...args) {
    http.createServer((req, res) => {

      const done = () => {
        res.statusCode = 404
        res.end('404')
      }
      this.router.action(req, res, done)
    }).listen(...args)
  }
}

module.exports = App